home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj008.zip / PORTING.ZIP / DLLSTUFF.C < prev    next >
C/C++ Source or Header  |  1992-06-08  |  3KB  |  128 lines

  1. // File DLLstuff.c contains C support routines needed by the Fortran
  2. // DLL.
  3.  
  4. #include <stdio.h>
  5. #ifdef NULL
  6. #undef NULL
  7. #endif
  8.  
  9. #include <windows.h>
  10.  
  11. // typedef and declaration for the message handler callback
  12. typedef BOOL (FAR PASCAL *LPHANDLER) (LPSTR);
  13. LPHANDLER lpDoIt;
  14.  
  15. // typdefs and declarations for address-setting callbacks
  16. typedef BOOL (FAR PASCAL *LPSETI) (LPSTR, long *);
  17. LPSETI lpSetI;
  18. typedef BOOL (FAR PASCAL *LPSETR) (LPSTR, float *);
  19. LPSETR lpSetR;
  20.  
  21. // saved ID for the window the app has told us to use for updates
  22.  
  23. HWND hWndScreen;
  24.  
  25. BOOL FAR PASCAL init_handler (LPHANDLER);
  26. BOOL FAR PASCAL init_lpsetI (LPSETI);
  27. BOOL FAR PASCAL init_lpsetR (LPSETR);
  28. BOOL FAR PASCAL init_window (HWND);
  29.  
  30. void _fortran setIntAddr (LPSTR, long *);
  31. void _fortran setRealAddr (LPSTR, float *);
  32. void _fortran c_msg_hndlr (LPSTR, LPSTR);
  33. void _fortran c_update_window (LPSTR);
  34. void _fortran bombOut (LPSTR);
  35. void _fortran WinYield (void);
  36. void _fortran doMsg (LPSTR, LPSTR);
  37.  
  38. void FAR PASCAL FatalAppExit (WORD, LPSTR);
  39.  
  40. // DLL initialisation routines
  41.  
  42. // Save the pointer to the message-handling function
  43. BOOL FAR PASCAL init_handler (LPHANDLER lpHnd)
  44. {
  45.    
  46.    lpDoIt = lpHnd;
  47.    return(TRUE);
  48. }
  49.  
  50. // Save the pointer to the address-setting function for ints
  51. BOOL FAR PASCAL init_lpsetI (LPSETI lpHnd)
  52. {
  53.    
  54.    lpSetI = lpHnd;
  55.    return(TRUE);
  56. }
  57.  
  58. // Save the pointer to the address-setting function for reals
  59. BOOL FAR PASCAL init_lpsetR (LPSETR lpHnd)
  60. {
  61.    
  62.    lpSetR = lpHnd;
  63.    return(TRUE);
  64. }
  65.  
  66. // Save a window ID
  67. BOOL FAR PASCAL init_window(HWND hWnd)
  68. {
  69.    
  70.    hWndScreen = hWnd;
  71.    return(TRUE);
  72. }
  73.  
  74. // This uses SDK calls to present a message box from within the DLL
  75. void _fortran doMsg (LPSTR title, LPSTR msg)
  76. {
  77.    MessageBox (NULL, msg, title, MB_OK );
  78.    return;
  79. }
  80.  
  81. // Whereas this calls the message handler in the main app to print for us
  82. void _fortran c_msg_hndlr( LPSTR title, LPSTR msg )
  83. {
  84.    (lpDoIt)(msg);
  85.    return;
  86. }
  87.  
  88. // update a window in the main app. This version changes the text of a 
  89. // static text control, but you could call InvalidateRect and
  90. // UpdateWindow to send a WM_PAINT message.
  91. void _fortran c_update_window (LPSTR msg)
  92. {
  93.    SetWindowText(hWndScreen, msg);
  94.    return;
  95. }
  96.  
  97. // return the address of a long int to the caller
  98. void _fortran setIntAddr (LPSTR var, long *Num1)
  99. {
  100.    (lpSetI)(var, Num1);
  101.    return;
  102. }
  103.  
  104. // return the address of a float to the caller
  105. void _fortran setRealAddr (LPSTR var, float *Num1)
  106. {
  107.    (lpSetR)(var, Num1);
  108.    return;
  109. }
  110.  
  111. // cause a Fatal exit
  112. void _fortran bombOut (LPSTR txt)
  113. {
  114.    FatalAppExit(0, txt);
  115.    return;
  116. }
  117.  
  118. // Process any outstanding events waiting. These may be characters
  119. // typed at the keyboard, WM_PAINT messages, etc.
  120. void _fortran WinYield()
  121. {
  122.    MSG msg;
  123.    while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
  124.       TranslateMessage(&msg);
  125.       DispatchMessage(&msg);
  126.    }
  127. }
  128.